package com.zmn.mcc.dubbo.impl.staff.archives;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.mcc.common.dto.staff.archives.StaffArchivesSimpleDRO;
import com.zmn.mcc.dubbo.interfaces.staff.archives.StaffArchivesRemoteListService;
import com.zmn.mcc.model.entity.staff.staffarchives.StaffArchives;
import com.zmn.mcc.services.interfaces.staff.staffarchives.StaffArchivesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.util.Objects;

/**
 * 员工档案接口实现类
 */
@Slf4j
public class StaffArchivesRemoteListServiceImpl implements StaffArchivesRemoteListService {

    @Resource
    StaffArchivesService staffArchivesService;

    @Override
    public ResponseDTO<StaffArchivesSimpleDRO> getByStaffId(@NotNull(message = "员工ID不能为空") @Positive(message = "员工ID必须为大于0的正整数") Integer staffId) {
        StaffArchives staffArchives = staffArchivesService.findByStaffId(staffId);

        if (Objects.isNull(staffArchives)) {
            log.error("该员工没有档案信息，staffId:{}", staffId);
            return ResponseDTO.fail("该员工没有档案信息，staffId:" + staffId);
        }

        StaffArchivesSimpleDRO staffArchivesSimpleDRO = new StaffArchivesSimpleDRO();
        BeanUtils.copyProperties(staffArchives, staffArchivesSimpleDRO);
        return ResponseDTO.success(staffArchivesSimpleDRO);
    }
}